<template>
    <van-row class="profile">
        <van-nav-bar
          title="我的信息"
          left-arrow
          @click-left="onClickLeft"
        />
        <van-col span="24"class="profile-conten">
            <div class="portrait">
                <van-image
                  round
                  width="10rem"
                  height="10rem"
                  :src="imgUrl"
                />
            </div>
            <!--账号信息-->
            <div class="profile-group">
                <van-cell-group>
                    <van-cell>
                        <span slot="title">姓名：{{ userInfo.userName }}</span>
                    </van-cell>
                    <van-cell>
                        <span slot="title">学号：{{ userInfo.userAccount }}</span>
                    </van-cell>
                    <van-cell is-link @click="train">
                        <span slot="title">培训记录</span>
                    </van-cell>
                    <van-cell is-link @click="notice">
                        <span slot="title">通知</span>
                    </van-cell>
                    <van-cell @click="modify">
                        <span slot="title" >密码修改</span>
                    </van-cell>
                </van-cell-group>
            </div>

        <!--    &lt;!&ndash;通用&ndash;&gt;
            <div class="profile-group">
                <van-cell-group>
                    <span slot="title" class="profile-group-title">通用</span>
                    <van-cell @click="clearLocalStorage()">
                        <a slot="title">清除数据缓存</a>
                        <span>解决数据一直获取不到</span>
                    </van-cell>
                    <van-cell>
                        <span @click="checkVersion()" slot="title">版本号</span>
                        <span>V1.0.0</span>
                    </van-cell>
                    <van-cell @click="feedback()">
                        <span slot="title">意见反馈</span>
                        <span>跟作者吐槽</span>
                    </van-cell>
                </van-cell-group>
            </div>-->


            <!--按钮-->
            <div class="profile-group">
                <van-cell-group>
                    <span slot="title"/>
                    <van-cell class="profile-group-button" @click="quit()">
                        <span slot="title">
                            退出当前账号
                        </span>
                    </van-cell>
                </van-cell-group>
            </div>

        </van-col>
    </van-row>
</template>

<script>
    import {Toast} from 'vant';
    import storage from "../../../model/storage";

    export default {
        name: "Profile",
        data() {
            return {
                // userName: '张三',
                // userAccount: '1993315415',
                userInfo: {
                    userName: '',
                    userAccount: ''
                },
                imgUrl: require('../../images/my.jpg'),
            };
        },
        mounted() {
            this.getStuInfo();
            let user = storage.get("user");
        },
        methods: {
            getStuInfo() {
                // let param = window.localStorage.getItem(account);
                const param = window.localStorage.getItem('account');
                const role = window.localStorage.getItem('role');
                if (role == 2) {
                    this.req.post("student/info",{account: param}).then(req => {
                    // let { code,data,msg } = req;
                    // console.log(req);
                    if (req.code === 200) {
                        this.userInfo.userName = req.data.stu_name;
                        this.userInfo.userAccount = req.data.stu_number;
                    } else {
                        Notify({ type: 'danger', message: '用户信息获取失败' });
                    }
                  });
                }else{
                    Notify({ type: 'danger', message: '用户信息获取失败' });
                }
            },
            /*clearLocalStorage() {
                storage.remove("schedules");
                storage.remove("scores");
                Toast.success("已清除缓存！")
            },
            checkVersion() {
                Toast.success('已经是最新版本')
            },
            feedback(){
                Toast.fail("反馈不了的，别点了")
            },*/
            train(){
                this.$router.push('/train')
            },
            notice(){
                this.$router.push('/notice')
            },
            modify(){
                this.$router.push('/modify')
            },
            quit() {
                localStorage.removeItem('token');//将本地token置空，退出登录
                localStorage.removeItem('role');
                localStorage.removeItem('account');
                // localStorage.removeItem('username');
                this.$router.push({path: "/login"}) //退出后，跳转到登录页面
            },
            onClickLeft() {
                this.$router.push("/schedule");
            }
        }
    }
</script>

<style scoped>
    .profile-group {
        padding-top: 20px;
    }
    .profile-group-title {
        color: var(--main-white);
    }
    .profile-group-button {
        color: var(--main-red);
        text-align: center;
    }
    .portrait{
        width: 100%;
        margin-top: 15px;
    }
    .van-image{
        margin-left: 50%;
        transform: translate(-50%, 0);
    }
</style>